package com.ruoyi.mes.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.mes.vo.buy.BuyInHouVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.mes.domain.BuyInhou;
import com.ruoyi.mes.service.IBuyInhouService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 采购入库Controller
 *
 * @author LongAndHao
 * @date 2023-04-04
 */
@Api(tags = "采购入库")
@RestController
@RequestMapping("/mes/buyinhou")
public class BuyInhouController extends BaseController
{

    @Autowired
    private IBuyInhouService buyInhouService;

    /**
     * 查询采购入库列表
     */
    @ApiOperation(value = "查询采购入库列表")
    @PreAuthorize("@ss.hasPermi('mes:buyinhou:list')")
    @GetMapping("/list")
    public TableDataInfo list(BuyInhou buyInhou) {
        startPage();
        List<BuyInhou> list = buyInhouService.selectBuyInhouList(buyInhou);
        return getDataTable(list);
    }

    /**
     * 导出采购入库列表
     */
    @ApiOperation(value = "导出采购入库列表")
    @PreAuthorize("@ss.hasPermi('mes:buyinhou:export')")
    @Log(title = "采购入库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BuyInhou buyInhou) {
        List<BuyInhou> list = buyInhouService.selectBuyInhouList(buyInhou);
        ExcelUtil<BuyInhou> util = new ExcelUtil<BuyInhou>(BuyInhou.class);
        util.exportExcel(response, list, "采购入库数据");
    }

    /**
     * 获取采购入库详细信息
     */
    @ApiOperation(value = "获取采购入库详细信息")
    @PreAuthorize("@ss.hasPermi('mes:buyinhou:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(buyInhouService.selectBuyInhouById(id));
    }

    /**
     * 新增采购入库
     */
    @ApiOperation(value = "新增采购入库")
    @PreAuthorize("@ss.hasPermi('mes:buyinhou:add')")
    @Log(title = "采购入库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BuyInhou buyInhou) {
        return toAjax(buyInhouService.insertBuyInhou(buyInhou));
    }

    /**
     * 修改采购入库
     */
    @ApiOperation(value = "修改采购入库")
    @PreAuthorize("@ss.hasPermi('mes:buyinhou:edit')")
    @Log(title = "采购入库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BuyInhou buyInhou) {
        return toAjax(buyInhouService.updateBuyInhou(buyInhou));
    }

    /**
     * 删除采购入库
     */
    @ApiOperation(value = "删除采购入库")
    @PreAuthorize("@ss.hasPermi('mes:buyinhou:remove')")
    @Log(title = "采购入库", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(buyInhouService.deleteBuyInhouByIds(ids));
    }

    //****************

    /**
     * 入库
     * @param buyInHouVo
     * @return
     */
    @PostMapping("/inHou")
    public AjaxResult inHou(@RequestBody BuyInHouVo buyInHouVo){
        return buyInhouService.inHou(buyInHouVo);
    }
}
